function FireWall($scope, $http, $timeout) {

    function rule() {
        this.proto = "any";
		this.ipv = 4;
		this.srcip = "any";
		this.srcport = 0;
		this.dstip = "any";
		this.dstport = 0;
		this.action = "ALLOW";
		this.log = "yes";
		this.uid = "changeme";
		this.coment = "Comment";
    }

    $scope.fwrules = new Array();

    $scope.tmpRule = new rule();

    $scope.tmpAddRule = function(){
        $scope.fwrules.push($scope.tmpRule);
		$scope.tmpRule = new rule();
    }
	
	$http.get("fwrules.xml").
		success(function(data, status, headers, config) {
			$scope.log = data;
		}).error(function(data, status, headers, config){
			alert(status);
			alert(headers);
		});

	$scope.doplot = function(){
		$http.get("log.txt").
			success(function(data, status, headers, config) {
				var data = $scope.parselog(data);
				$.jqplot('chart', [data], {
					title: 'fw564 rules stat',
					series: [{renderer: $.jqplot.BarRenderer}],
					axesDefaults:{
						tickRenderer: $.jqplot.CanvasAxisTickRenderer
					},
					axes: {
						xaxis: {
							renderer: $.jqplot.CategoryAxisRenderer
						}
					}
				}).replot();
				$timeout($scope.doplot, 10000);
			}).error(function(data, status, headers, config){
				$timeout($scope.doplot, 10000);
			});		
	}
	
	$scope.doplot();
	
	$scope.parselog = function(log){
		var retn = {};
		var entries = log.split('\n');
		for(entry in entries){
			var name = entries[entry];
			if(typeof retn[name] == 'undefined'){
				retn[name] = 1;
			}else{
				retn[name] = retn[name] + 1;
			}
		}
		
		var rtnarr = [];
		for(name in retn){
			rtnarr.push([name, retn[name]]);
		}
		return rtnarr;/*
		return [
			['rule name 1', 17], ['rule name 2', 2], ['tcp', 72]
		];*/
	}
}
